package ylsb.service;


import org.springframework.stereotype.Service;
import ylsb.dao.YltpYinjinMapper;
import ylsb.model.Yiyonghaocai;
import ylsb.model.YltpYinjin;
import ylsb.model.YltpYinjinExample;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

@Service
public class YltpyinjinService {

    @Resource
    YltpYinjinMapper ddMapper;

    public List<YltpYinjin> findyinjinlist(String xiangmuId){
        YltpYinjinExample mmExample=new YltpYinjinExample();
        mmExample.createCriteria().andXiangmuidEqualTo(xiangmuId);
        mmExample.setOrderByClause("ordernumber ASC");
        return  ddMapper.selectByExample(mmExample);

    }

    public boolean add (YltpYinjin ddYltpYinjin){
        return ddMapper.insert(ddYltpYinjin)==1;
    }

    public boolean isexistByxiangmuId(String xiangmuId){
        YltpYinjinExample mmExample=new YltpYinjinExample();
        YltpYinjinExample.Criteria criteria=mmExample.createCriteria();
        criteria.andXiangmuidEqualTo(xiangmuId);
        return  ddMapper.selectByExample(mmExample).size()>0;
    }

    public boolean deleteByxiangmuId(String xiangmuId){
        YltpYinjinExample mmExample=new YltpYinjinExample();
        YltpYinjinExample.Criteria criteria=mmExample.createCriteria();
        criteria.andXiangmuidEqualTo(xiangmuId);
        return  ddMapper.deleteByExample(mmExample)>=0;
    }

    public List<Map<String, Object>> findBiaojuelist(String mmxiangmuId, String mmuserId){
        return ddMapper.findBiaojuelist(mmxiangmuId,mmuserId);
    }
    public Integer getVoteCount(String ppxiangmuId){
        List<Map<String, Object>> list=ddMapper.findByXiangmuId(ppxiangmuId);
        return list == null ? 0 : list.size();
    }

    public YltpYinjin findOne(String id){
        return ddMapper.selectByPrimaryKey(id);
    }

}
